<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import type { FormProps } from "./utils/types";
import { usePublicHooks } from "../hooks";
import IconSelect from "@/components/ReIcon/src/Select.vue";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    higherDeptOptions: [],
    parentId: 0,
    className: "",
    classSort: 0,
    classTypeID: 2,
    status: 0,
    classIcon: "",
    id: 0
  })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>
<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-row :gutter="30">
      <re-col>
        <el-form-item label="根类别">
          <el-cascader
            class="w-full"
            v-model="newFormInline.parentId"
            :options="newFormInline.higherDeptOptions"
            :props="{
              value: 'id',
              label: 'className',
              emitPath: false,
              checkStrictly: true
            }"
            clearable
            filterable
            placeholder="请选择根类别"
          >
            <template #default="{ node, data }">
              <span>{{ data.className }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="类别名称" prop="className">
          <el-input
            v-model="newFormInline.className"
            clearable
            placeholder="请输入类别名称"
          />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="排序">
          <el-input-number
            v-model="newFormInline.classSort"
            :min="0"
            :max="9999"
            controls-position="right"
          />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="应用图标">
          <IconSelect v-model="newFormInline.classIcon" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="类别状态">
          <el-switch
            v-model="newFormInline.status"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            active-text="启用"
            inactive-text="停用"
            :style="switchStyle"
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>
